<template>
	<view class="box">
		<view class="title">
			<!-- 头部 -->
			<view class="title-top">
				<view class="box-news">
					<!-- 个人信息介绍 -->
					<view class="box-image">
						<image :src="getStaticFilePath('/main/main-TX.png')"></image>
					</view>
					
					<view class="box-information">
						<view class="box-name">
							{{ userinfo.sign == 'CUS-3' ? objVdengji.ORMTB417CA01 : objVdengji.ORMTB410CA10 }}
							<text v-if="objVdengji.ORMTB410CB02 >= 1" class="xingji-V">V
								<text class="">{{ objVdengji.ORMTB410CB02 }}</text>
							</text>
							<image v-if="objVdengji.ORMTB410CB04 == 1" class="chezhu-biaoshi"
								src="../../../static/images/chezhu.png" mode=""></image>
							<image v-if="objVdengji.ORMTB410CB03 == 1" class="chezhu-biaoshi"
								src="../../../static/images/fadanren.png" mode=""></image>
								<view v-if="userinfo.sign == 'CUS-2'" @click="xgmc" class="" style="color: #FF3300; padding-left: 20rpx;display: flex;padding-bottom: 10rpx;">
									<image style="width: 52rpx;height: 52rpx;" :src="getStaticFilePath('/home/nav/nav-XGBZ.png')" mode="widthFix"></image>
									<text>修改名称</text>
								</view>
						</view>
						<view class="box-phone">
							{{ userinfo.sign == 'CUS-3' ? objVdengji.ORMTB417CA00 : objVdengji.ORMTB410CA02 }}
						</view>
						
					</view>
				</view>
				<view class="box-abilty" @click="mainsetTap">
					<text class="iconfont iconshezhi"></text>
				</view>
			</view>
			<!-- 列表 -->
			<view class="title-list">
				<view class="enshrine">
					<view class="enshrine-num">
						{{ collection || 0 }}
					</view>
					<view class="enshrine-text">
						我的收藏
					</view>
				</view>
				<view class="enshrine" @click="clickCoupon">
					<view class="enshrine-num">
						{{ integral.KY }}
					</view>
					<view class="enshrine-text">
						优惠券
					</view>
				</view>
			</view>
		</view>
		<!-- 会员 -->
		<view class="center">
			<!-- 我的账户 -->
			<view class="account" @click="myaccountClick">
				<view class="mind">
					<view class="mind-name">
						我的账户
					</view>
					<view class="mind-abilty">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<!-- 余额 -->
				<view class="balance" v-if="userinfo.sign == 'CUS-2' || userinfo.sign == 'CUS-3'">
					<view class="mind-balance">
						<view class="balance-name">
							账户余额(元)
						</view>
						<view class="balance-num" v-if="AuthorizationOBJ.ORMTB417CA06 == 0">
							***
						</view>
						<view class="balance-num" v-else>
							{{ account }}
						</view>
					</view>
					<view class="available-balance">
						<view class="balance-name">
							可用余额(元)
						</view>
						<view class="balance-num" v-if="AuthorizationOBJ.ORMTB417CA06 == 0">
							***
						</view>
						<view class="balance-num" v-else>
							{{ available }}
						</view>
					</view>
				</view>
			</view>

			<!-- 功能模块 -->
			<view class="function">
				<view class="function_four pack">
					<view class="manage" v-if="userinfo.sign == 'CUS-2'" @click="childrenClick">
						<view class="left">
							<view class="iconfont iconzhanghaoguanli"
								style="font-size:48rpx;color: #0197F8;text-align: center;"></view>
							<view class="manage-text">
								子账户管理
							</view>
						</view>
						<view class="mind-abilty">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					
					<view class="manage" @click="userfpclick">
						<view class="left">
							<image style="width:70rpx; height: 60rpx;" class="iconfont"
								:src="getStaticFilePath('/home/nav/nav-FP.png')"></image>
							<view class="manage-text">
								票据管理
							</view>
						</view>
						<view class="mind-abilty">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<!-- @click="tjshClick" -->
					<view class="manage" v-if="objVdengji.ORMTB410CB13 == '1'">
						<view class="left">
							<view class="iconfont" style="text-align: center;">
								<image style="width: 56rpx;height: 56rpx;"
									:src="getStaticFilePath('/home/nav/nav-tjsh.png')" mode="widthFix"></image>
							</view>
							<view class="manage-text">
								调价审核
							</view>
						</view>
						<view class="mind-abilty">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<view v-if="userinfo.ORMTB410CB19 == '1'" class="manage" @click="dfydtjclick">
						<view class="left">
							<image style="width:70rpx; height: 70rpx;"
								:src="getStaticFilePath('/home/nav/nav-DFTJ.png')" mode="widthFix"></image>
							<view class="manage-text">代发统计</view>
						</view>
						<view class="mind-abilty">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<view class="manage" @click="dataStatisticsClick">
						<view class="left">
							<u-icon :name="getStaticFilePath('/home/nav/nav-TJ.png')" :size="65"
								style="margin-left: -10rpx;">
							</u-icon>
							<view class="grid-text" style="margin-left: 25rpx;">数据统计</view>
						</view>
						<view class="mind-abilty">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<view class="manage" v-if="userinfo.sign == 'CUS-2'" @click="txlClick">
						<view class="left">
							<u-icon :name="getStaticFilePath('/home/nav/nav-TXL.png')" :size="65"
								style="margin-left: -10rpx;">
							</u-icon>
							<view class="manage-text">
								通讯录
							</view>
						</view>
						<view class="mind-abilty">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
					<view class="manage" @click="phoneCallClick">
						<view class="left">
							<view class="iconfont iconlianxiwomen" style="font-size:40rpx;color: #faa700;"></view>
							<view class="manage-text" style="margin-left: 40rpx;">联系客服</view>
						</view>
						<view class="mind-abilty">
							<u-icon name="arrow-right"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			userinfo: JSON.parse(uni.getStorageSync('userinfo')),
			userinfoCusName: '',
			userinfoPhone: '',
			outLoginShow: false,
			collection: 0, //收藏
			integral: 0, //积分
			discount: 0, //优惠
			account: 0, //账户余额
			available: 0, //可用余额
			AuthorizationOBJ: '',
			objVdengji: {},
			phone: '13298226839',
		}
	},
	onShow() {
		if (this.userinfo.sign == 'CUS-3') {
			this.queryAuthorization()
		}
		if (this.userinfo.sign == 'CUS-1') {
		} else if (this.userinfo.sign == 'CUS-2' || this.userinfo.sign == 'CUS-3') {
			this.queryMoney()
		}
		this.getCollectionList()
		this.getIntegral()
		this.getVdengjiFun()
	},
	methods: {
		dataStatisticsClick() {
			uni.navigateTo({
				url: '../../datastatistics/index'
			})
		},
		xgmc(){//修改名称
			uni.navigateTo({
				url: '/pages/wallet/xgnc/index?name='+this.objVdengji.ORMTB410CA10
			})
		},
		// 积分
		async getIntegral() {
			let [err, res] = await uni.request({
				url: `${this.baseUrl}/orm/ormtb410/getIntegral`,
				method: 'POST',
				data: { ORMTB410ID: this.userinfo.ORMTB410ID }
			})
			if (res.data.code === 200) {
				this.integral = res.data.data
			}
		},
		outLoginConfirm() {
			uni.showLoading({
				title: '请求中',
				mask: true
			});
			uni.request({
				url: this.baseUrl + '/system/quit',
				method: 'POST',
				dataType: 'json',
				data: {
					PERTB005ID: this.userinfo.PERTB005ID
				},
				success: (res) => {
					console.log(res);
					if (res.data.code == 200) {
						uni.clearStorageSync()
						uni.reLaunch({
							url: '/pages/APPlogin/index'
						})
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
					uni.hideLoading();
				},
				fail: (res) => {
					this.$refs.uToast.show({
						title: res.errMsg,
						type: 'default',
						icon: false
					})
					uni.hideLoading();
				}
			});
		},
		getVdengjiFun() {
			uni.showLoading({
				title: '请求中...',
				mask: true
			});
			uni.request({
				url: this.baseUrl + '/orm/ormtb410/getLevel',
				method: 'POST',
				dataType: 'json',
				data: {
					ORMTB410ID: this.userinfo.ORMTB410ID, //用户ID
					ORMTB417ID: this.userinfo.ORMTB417ID  //子用户ID
				},
				success: (res) => {
					uni.hideLoading();
					if (res.data.code == 200) {
						// console.log(res)
						this.objVdengji = res.data.data
					} else if (res.data.code == 401) {
						// 退出子账户
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
						let tiemr = setTimeout(() => {
							this.outLoginConfirm()
							clearTimeout(tiemr)
						}, 2000)
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
				},
				fail: (res) => {
					uni.hideLoading();
					this.$refs.uToast.show({
						title: '服务器连接超时',
						type: 'default',
						icon: false
					})
				}
			});
		},
		queryAuthorization() { //查询子账户权限
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			uni.request({
				url: this.baseUrl + '/orm/ormtb417/selectAccess/' + this.userinfo.ORMTB417ID,
				method: 'GET',
				success: (res) => {
					uni.hideLoading();
					if (res.data.code == 200) {
						this.AuthorizationOBJ = res.data.data
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
				},
				fail: (res) => {
					uni.hideLoading();
					this.$refs.uToast.show({
						title: '服务器连接超时',
						type: 'default',
						icon: false
					})
				}
			});
		},
		getCollectionList() {
			uni.showLoading({
				title: '请求中...',
				mask: true
			});
			uni.request({
				url: this.baseUrl + '/set/settb403/selectPageList',
				method: 'POST',
				dataType: 'json',
				data: {
					SETTB403CA00: this.userinfo.PERTB005ID, //用户ID
					page: 1,
					limit: 10,
				},
				success: (res) => {
					uni.hideLoading();
					if (res.data.code == 200) {
						this.collection = res.data.count
					} else {

						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
				},
				fail: (res) => {
					if (this.countpageColl == this.pageColl) {
						this.status = "nomore"
					} else {
						this.status = "loadmore"
					}
					uni.hideLoading();
					this.$refs.uToast.show({
						title: '服务器连接超时',
						type: 'default',
						icon: false
					})
				}
			});
		},
		queryMoney() {
			uni.request({
				url: this.baseUrl + '/orm/ormtb410/selectORMTB410CA03',
				method: 'post',
				dataType: 'json',
				data: {
					ORMTB410ID: this.userinfo.ORMTB410ID,
				},
				success: (res) => {
					if (res.data.code == 200) {
						this.account = res.data.data.yEmoney
						this.available = res.data.data.kYMoney
					} else {
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				},
				fail: (res) => {
					uni.showToast({
						title: '服务器连接超时',
						duration: 5000,
						icon: 'none',
					});
				}
			});
		},
		myaccountClick() {
			if (this.userinfo.sign == 'CUS-1') {
				uni.navigateTo({
					url: '../../myaccountBig/index'
				})
			} else if (this.userinfo.sign == 'CUS-2' || this.userinfo.sign == 'CUS-3') {
				uni.navigateTo({
					url: '../../myaccount/index'
				})
			}
		},
		childrenClick() {
			uni.navigateTo({
				url: '/pages/mainChildAccount/index'
			})
		},
		txlClick() {
			uni.navigateTo({
				url: '/pages/shouquan/txl/index'
			})
		},
		userfpclick() {
			uni.navigateTo({
				url: '/pages/userfp/billManage/billManage'
			})
		},
		dfydtjclick() {
			uni.navigateTo({
				url: '/pages/daiOrde/dfydtj/index'
			})
		},
		mainsetTap() {
			uni.navigateTo({
				url: '/pages/mainSet/index'
			})
		},
		addresAdmin() {
			uni.navigateTo({
				url: '/pages/deliveryPlace/index'
			})
		},
		clickCoupon() {
			uni.navigateTo({
				url: '/pages/coupon/index'
			})
		},
		phoneCallClick() {
			uni.makePhoneCall({
				phoneNumber: '13298226839'
			});
		},
	}
}
</script>

<style lang="scss">
.box {
	background: #f5f1f1;
	height: 100vh;
}

.title {
	background-color: #0197f8;
	/*让下边出现边框 */
	border-bottom-right-radius: 20%;
	border-bottom-left-radius: 20%;
	border-bottom: #0197f8 solid 80rpx;
}

.title-top {
	display: flex;
	padding-top: 40rpx;
	justify-content: space-between;
	margin-left: 20rpx;
}

.box-news {
	display: flex;
}

.box-image image {
	width: 100rpx;
	height: 100rpx;
	border-radius: 50%;
	margin: 20rpx;
}

.box-information {
	margin-left: 5rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	margin-bottom: 8rpx;
}

.box-name {
	font-size: 36rpx;
	font-weight: 600;
	color: #FFFFFF;
	display: flex;
}

.box-phone {
	font-size: 28rpx;
	color: #FFFFFF;
}

.box-abilty {
	width: 100rpx;
	text-align: center;
	display: flex;
	align-items: center;
}

.box-abilty .iconfont {
	font-size: 28px;
	color: #FFF;
}

.title-list {
	margin-top: 40rpx;
	display: flex;
	justify-content: space-around;
	padding-bottom: 40rpx;
}

.enshrine {
	display: flex;
	flex-direction: column;
}

.enshrine-num {
	text-align: center;
	color: #FFFFFF;
	font-size: 30rpx;
	font-weight: 500;
	margin-bottom: 10rpx;
}

.enshrine-text {
	text-align: center;
	color: #FFFFFF;
	margin-top: 10rpx;
}

.center {
	width: 90%;
	display: flex;
	margin: 0 auto;
	border-radius: 20rpx;
	position: relative;
	flex-direction: column;
	top: -110rpx;
}

.account {
	margin-bottom: 20rpx;
	padding: 30rpx;
	box-sizing: border-box;
	width: 100%;
	border-radius: 20rpx;
	background-color: #FFFFFF;
}

.mind {
	display: flex;
	justify-content: space-between;
}

.mind-name {
	font-size: 36rpx;
	font-weight: 600;
}

.balance {
	display: flex;
	justify-content: space-between;
	text-align: center;
}

.balance-name {
	margin-top: 10rpx;
	margin-bottom: 20rpx;
}

.shadow {
	height: 20rpx;
}

.function {
	margin-bottom: 20rpx;
	border-radius: 20rpx;
	background: #fff;

	.tit {
		font-size: 40rpx;
		margin: 20rpx 0 50rpx;
		padding-left: 15rpx;
	}
}

.function_four {
	padding: 0 20rpx;

	.left {
		display: flex;
		align-items: center;

		.manage-text {
			margin-left: 22rpx;
		}
	}
}

.function_four>view {
	font-size: 32rpx;
}

.manage {
	position: relative;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 30rpx 0rpx;
	border-bottom: 1rpx solid #f5f1f1;
}

.manage-text {
	width: 100%;
	text-align: center;
}

.xingji-V {
	color: #FFCC00;
	padding-left: 20rpx;
	font-size: 40rpx;
}

.chezhu-biaoshi {
	width: 40rpx;
	height: 40rpx;
	padding-left: 20rpx;
	padding-top: 6rpx;
}
</style>
